<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>添加品类url</title>
	    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
       <div class="easyui-container-fluid">
          <div class="easyui-panel" style="border: none;">
            <div class="nav" id="nav"></div> 
            <div class="easyui-panel">
              <form id="ff" method="post">
                  <div style="margin-top:  10px">
                      <label class="item-label">品类：</label>
                      <input class="easyui-textbox" style="width:100px;" type="text" name="product_cate"  />
                      <label class="item-label">级别：</label>
                      <input class="easyui-numberspinner" style="width:100px;" type="text" name="product_level"  />
                  </div>
                 <div style="margin-top:  30px;margin-bottom:30px;">
                     <label class="item-label">url：</label>
                     <input type="easyui-textbox" style="width: 500px" class="easyui-textbox" name="product_url"  id="product_url" />
                 </div>
                  <div style="margin-bottom:20px;">
                      <label class="item-label">禁用字：</label>
                      <input name="disable_words" class="easyui-tagbox" value="" style="width:50%;min-height:60px;" data-options="multiline:true"/>
                  </div>
                  <div style="margin-bottom:20px;">
                      <label class="item-label">正则表达式：</label>
                      <input name="disable_zz" class="easyui-tagbox" value="" id = "disable_zz" style="width:50%;min-height:60px;" data-options="multiline:true"/>
                  </div>
                  <div style="margin-left: 100px;margin-bottom: 20px;">
                    <a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">保存</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancel()" style="width:80px">取消</a>
                </div>
              </form>     
            </div>
          </div> 
       </div>  
    </body>
    <script type="text/javascript">
         var id = getQueryParameter("id");
        $(function(){
          setNav();
          initFormData();
        });
        function initFormData(){
          if(id){
            $.ajax({
              url:config.url +"/jdrules/"+id,
              type:'get',
              data:{},
              xhrFields:{withCredentials:true},
              success:function(data){
                //填充表单
                  if(data){
                      if(!data.matchWords){
                          data.matchWords = [];

                      }
                      if(!data.disable_words){
                          data.disable_words = [];
                      }
                      if(!data.disable_zz){
                          data.disable_zz = [];
                      }
                      $("#ff").form("load",changeProperty2String(data));
                  }   
              },
              error:function(){

              }
            });
          }
        }
         function submitForm(){
            $("#ff").form("submit",{
                  onSubmit:function(){
                    var formData = getFormData(document.getElementById("ff"));
                      formData['product_url'] = $("#product_url").textbox('getValue');
                    if(!formData.product_cate || !formData.product_url){
                        $.messager.alert("提示","请输入，不允许为空","error");
                        return;
                    }
                    var method = "POST";
                    if(id){
                      method = "PATCH";
                      formData.id = id;
                    }
                      if(formData['disable_words'] && typeof formData['disable_words'] === 'string'){
                          formData['disable_words'] = [formData['disable_words']]
                      }
                      formData['disable_zz'] = $("#disable_zz").tagbox("getValues");
                    $.ajax({
                       url:config.url+"/jdrules",
                       type:method,
                       data:JSON.stringify(formData),
                       dataType:'json',
                       contentType:'application/json;charset=UTF-8',
                       xhrFields:{withCredentials:true},
                       beforeSend:function(){
                           $.messager.progress({
                               title:"请稍等",
                               interval:50,
                               text:"操作进行中..."
                           });
                       },
                       complete:function(){
                            $.messager.progress("close");
                       },
                       success:function(data){
                            $.messager.alert("提示","操作成功","info",function(){
                               window.parent.closeCurrentTab(true);
                            });
                       },
                       error:function(XMLHttpRequest,textStatus,thrown){
                            $.messager.alert("提示","操作失败","error");
                       }
                    });
                    return false;
                 }
            });
         }
         function cancel(){
             window.parent.closeCurrentTab();
         }
    </script>
</html>
